import { AppModel } from '../../../../model/AppModel';
import { createUIWidgetMenu } from '../BlockPackage'

export default {

    category: Blockly.Categories.operators ,
    color: [
        Blockly.Colours.operators.primary,
        Blockly.Colours.operators.secondary,
        Blockly.Colours.operators.tertiary
    ] ,

    previousStatement: false ,
    nextStatement: false ,
    hat: false ,

    extensions: ['colours_operators', 'output_number'] ,

    init(model: AppModel) {
        this.appendDummyInput()
            .appendField("滑块")
            .appendField(createUIWidgetMenu(model, "Slider"), 'uislider')
            .appendField("数值")
        Blockly.Extensions.apply("output_number", this)
    } ,

    run (args: any, util: any, runtime: any) {
        return runtime.uiwidgetEvent[args.uislider]
    } ,

    coder: {
        JavaScript(block: any, coder: any, model: AppModel) {
            let wid = block.getFieldValue('uislider')
            let widget = model.ui.mapWidgets[wid]
            return [`be.var["${widget.name}"]`, coder.ORDER_ATOMIC]
        }
    }
}
